package org.cuckoocs.tool.key;


/**
 * two positive int number convert to a unique positive int number. but ,both of the two num must less than 0b111111111111111(32767)
 * 
 * 32bit-->int
 * 2_15_15
 * 00_000000000000000_000000000000000
 * @author shuntao
 *
 */
public class I2ck2 {
	
	static final int _l16 = 0b0_000000000000000_0_111111111111111;
	static final int _r16 = 0b0_111111111111111_0_000000000000000;
	
	static final int _ln16 = 0b1_000000000000000_1_111111111111111;
	static final int _rn16 = 0b1_111111111111111_1_000000000000000;
	
	static final int _to_positive1 = 0b0000000000000000_1000000000000000;
	static final int _to_positive2 = 0b1000000000000000_0000000000000000;
	static final int _to_positive3 = 0b1000000000000000_1000000000000000;
	
	private static final int min = -0b11111_11111_11111;
	private static final int max =  0b11111_11111_11111;
	
	public static int ck(int k1, int k2){
		if (k1 < min || k1 > max || k2 < min || k2 > max) {
			return -1;
		}
		
		if (k1 < 0 && k2 < 0) {
			return (~k1+1 << 16 | ~k2+1) | _to_positive3;
		}else if (k1 < 0) {
			return (~k1+1 << 16 | k2) | _to_positive3;
		}else if (k2 < 0) {
			
		}
		
		return k1 << 16 | k2;
//		int left = 0, right = 0;
//		left = k1 < 0 ? ((~k1+1) | _to_positive) << 16 : k1 << 16;
//		right = k2 < 0? (~k2+1) | _to_positive : k2;
//		return left | right;
	}
//	
//	public static int[] uck(int k){
//		return new int[]{(k & _r15) >> 15, k & _l15};
//	}
//	
//	public static int uckl(int k){
//		return (k & _r15) >> 15;
//	}
//	
//	public static int uckr(int k){
//		return k & _l15;
//	}
	
}
